package com.yuejian_06.yuejian_06.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.Toast;

import com.yuejian_06.yuejian_06.Listener.LoginListener;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.activity.ClubSearchActivity;
import com.yuejian_06.yuejian_06.adapter.ClubAdapter;
import com.yuejian_06.yuejian_06.bean.ClubBean;
import com.yuejian_06.yuejian_06.model.ClubModel;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ClubFragment extends Fragment {
    RecyclerView recyclerView;
    ImageButton btn_search;

    private LoginListener<List<ClubBean>> Listener=new LoginListener<List<ClubBean>>() {
        @Override
        public void onResponse(List<ClubBean> o) {
            List<ClubBean> mDataList=o;
            recyclerView.setAdapter(new ClubAdapter(getActivity(),mDataList));//设置适配器
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(getActivity().getApplicationContext(),"失败了",Toast.LENGTH_SHORT).show();

        }
    };

    public ClubFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_club, container, false);
        btn_search=(ImageButton) view.findViewById(R.id.club_search);
        recyclerView = (RecyclerView) view.findViewById(R.id.club_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));// 布局
        ClubModel clubModel=new ClubModel();
        clubModel.clubList(Listener);
        //进入俱乐部搜索页面
        btn_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), ClubSearchActivity.class);
                startActivity(intent);
            }
        });

        return view;
    }



}
